<?php
	class CategoryBO 
	{   
		private $category;

		function __construct($id = null)
		{
			if(isset($id))
				$this->category=R::load('category',$id);
			else
				$this->category=R::dispense('category');			
		}

		public function getName()
		{
			return $this->category->name;
		}
		
		public function getID()
		{
			return $this->category->id;
		}
	
		
		public function getParent()
		{
			$parent=$this->category->category;
			if(isset($parent))
				return  $parent;
			else
				return R::dispense('category');
		}
		
		public function getSeoID()
		{
			return $this->category->seoid;
		}
		
		public function getSubCategories()
		{		  
			$categoryBOs=array();
			$categories = $this->category->ownCategory;
			foreach($categories as $k => $category)
			{
				array_push($categoryBOs,BOFactory::getCategoryBO($category->id));
			}				
			return $categoryBOs;
		}
		
		public function getProductBOs()
		{
			$productBOs=array();
			$products = $this->category->withCondition( ' typecode in (2,4) ' )->sharedProduct;
			foreach($products as $k => $product)
			{
//				if($product->typecode == 2 or $product->typecode == 4)
				array_push($productBOs,BOFactory::getProductBO($product->id));
			}				
			return $productBOs;
		}
		
	}